home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’95 / Menu Controls / HackMenu.cp < prev    next >
Encoding:
Text File  |  1995-06-24  |  2.7 KB  |  103 lines  |  [TEXT/MPS ]

  1. // HackMenu.cp
  2. // Copyright © 1994-95 by Apple Computer, Inc. All rights reserved.
  3.  
  4. #ifndef __HACKMENU__
  5. #include "HackMenu.h"
  6. #endif
  7.  
  8. // MacApp
  9.  
  10. #ifndef __UVIEWSERVER__
  11. #include "UViewServer.h"
  12. #endif
  13.  
  14. #ifndef __UWINDOW__
  15. #include "UWindow.h"
  16. #endif
  17.  
  18. #ifndef __UMACAPPUTILITIES__
  19. #include "UMacAppUtilities.h"
  20. #endif
  21.  
  22. //========================================================================================
  23. // CLASS THackMenu
  24. //========================================================================================
  25. #undef Inherited
  26. #define Inherited TTearOffMenuView
  27.  
  28. #pragma segment AInit
  29. MA_DEFINE_CLASS_M1(THackMenu, Inherited);
  30.  
  31. //----------------------------------------------------------------------------------------
  32. // THackMenu Constructor
  33. //----------------------------------------------------------------------------------------
  34. #pragma segment AInit
  35.  
  36. THackMenu::THackMenu()
  37. {
  38. }
  39.  
  40. //----------------------------------------------------------------------------------------
  41. // THackMenu::IHackMenu
  42. //----------------------------------------------------------------------------------------
  43. #pragma segment AInit
  44.  
  45. void THackMenu::IHackMenu(ResNumber menuID, ResNumber windowID)
  46. {
  47.     TWindow* window = gViewServer->NewTemplateWindow(windowID, NULL);
  48.     FailNIL(window);
  49.     TView* palette = window->FirstSubView();
  50.     FailNonObject(palette);
  51.     window->RemoveSubView(palette);
  52.     palette->fLocation = gZeroVPt;
  53.     window = (TWindow*) FreeIfObject(window);
  54.     
  55.     window = gViewServer->NewTemplateWindow(windowID, NULL);
  56.     
  57.     this->ITearOffMenuView(menuID, palette->fSize.h, palette->fSize.v, window);
  58.  
  59.     this->AddSubView(palette);
  60. }
  61.  
  62. //========================================================================================
  63. // CLASS THackView
  64. //========================================================================================
  65. #undef Inherited
  66. #define Inherited TView
  67.  
  68. #pragma segment AInit
  69. MA_DEFINE_CLASS_M1(THackView, Inherited);
  70.  
  71. //----------------------------------------------------------------------------------------
  72. // THackView Constructor
  73. //----------------------------------------------------------------------------------------
  74. #pragma segment AInit
  75.  
  76. THackView::THackView()
  77. {
  78. }
  79.  
  80. //----------------------------------------------------------------------------------------
  81. // THackView::IHackMenu
  82. //----------------------------------------------------------------------------------------
  83. #pragma segment AInit
  84.  
  85. void THackView::DoEvent(EventNumber eventNumber,
  86.                         TEventHandler* source,
  87.                         TEvent* event) // override
  88. {
  89.     if (eventNumber == mButtonHit)
  90.     {
  91.         TWindow* window = GetWindow();
  92.         if (window)
  93.         {
  94.             TCloseWindowCommand* closer = new TCloseWindowCommand;
  95.             closer->ICloseWindowCommand(cClose, window);
  96.             PostCommand(closer);
  97.         }
  98.     }
  99.     else
  100.         Inherited::DoEvent(eventNumber, source, event);
  101. }
  102.  
  103.